<?php
namespace app\common\model\user;

use app\common\model\BaseModel;

/**
 * 用户余额变动明细模型
 */
class BankCard extends BaseModel
{
    protected $name = "user_bank";
    protected $pk = "id";
    public function addCard($data)
    {
        unset($data['token']);
        $w[] = ['bank_code','=',$data['bank_code']];
        $w[] = ['bank_type','=',$data['bank_type']];
        $w[] = ['user_id','=',$data['user_id']];
        $w[] = ['is_delete','=',0];
        $check = $this->where($w)->find();
        if($check){
            $this->error = '已有此卡号';
            return false;
        }
        $res = $this->save($data);

        return $res;
    }
    public function editCard($data)
    {
        unset($data['token']);
        $w[] = ['bank_code','=',$data['bank_code']];
        $w[] = ['bank_type','=',$data['bank_type']];
        $w[] = ['user_id','=',$data['user_id']];
        $w[] = ['id','<>',$data['id']];
        $w[] = ['is_delete','=',0];
        $check = $this->where($w)->find();
        if($check){
            $this->error = '已有此卡号';
            return false;
        }
        $res = $this->where(array('id'=>$data['id']))->update($data);

        return $res;
    }

}